using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

/// <summary>
/// 场景切换模块
/// </summary>
public class 场景控制器 : 单例_基础管理器<场景控制器>
{
    /// <summary>
    /// 场景切换同步
    /// </summary>
    /// <param name="name"></param>
    /// <param name="函数"></param>
    public void 加载场景_同步加载(string name, UnityAction 函数)
    {
        //场景同步加载
        SceneManager.LoadScene(name);
        函数();
    }


    /// <summary>
    /// 携程异步加载场景
    /// </summary>
    /// <param name="name"></param>
    /// <param name="函数"></param>
    public void 加载场景_异步加载(string name, UnityAction 函数)
    {
        帧更新控制器.获取实例.开启携程(携程加载场景(name, 函数));
    }
    
    private IEnumerator 携程加载场景(string name,UnityAction 函数)
    {
        AsyncOperation ao = SceneManager.LoadSceneAsync(name);
        //进度属性
        while (!ao.isDone)
        {
            事件中心.获取实例.事件触发("加载场景_进度条更新", ao.progress);
            yield return ao.progress;
        }

        函数();
    }
}
